﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web.Mvc;
using DevelopmentKit.Extensions.Framework;

namespace DevelopmentKit.Extensions.MvcContrib
{
    public static class EnumExtensions
    {
            /// <summary>
        /// 获得某个Enum类型的绑定列表<br/>
        /// </summary>
        /// <param name="en">枚举的类型，例如：typeof(Sex)</param>
        /// <returns>
        /// 键值集合 key为Man,value为"男"(特性的描述值,如果没有特性描述就显示英文的字段名)       
        /// </returns>
        public static IList<SelectListItem> ToSelectListItems(this Enum en)
            {
                return en.ToDictionary().Select(x => new SelectListItem{Text = x.Key,Value = x.Value.ToString(CultureInfo.InvariantCulture)}).ToList();
            }
    }
}